'''

    登录的模块

'''
import time,logging

from Base.Base import Base
from selenium.webdriver.common.by import By

class Page1(Base):
    logging.debug('start')
    dl_loc = (By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def dl(self):
        self.click(self.dl_loc)

    # 断言1 是否成功跳转到 ‘会员登录’
    yq1_loc = (By.XPATH,'/html/body/div[4]/div/div[1]/div[1]/span[1]')
    def yq1(self):
        return self.text(self.yq1_loc)

    # 输入用户名，输入密码
    username_loc = (By.XPATH,'//*[@id="theForm"]/div[1]/span[2]/input')
    def username(self):
        self.send_keys(self.username_loc,'19064013675')

    password_loc = (By.XPATH,'//*[@id="theForm"]/div[2]/span[2]/input')
    def password(self):
        self.send_keys(self.password_loc,'123456')

    # 点击登录
    login_bt_loc = (By.XPATH,'//*[@id="theForm"]/div[5]/a')
    def login_bt(self):
        self.click(self.login_bt_loc)

    # 断言2 是否登录成功
    yq2_loc = (By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def yq2(self):
        return self.text(self.yq2_loc)

    logging.debug('last')

    def a3mall_login_001(self):
        self.open_url('http://10.59.9.12:7001/')
        self.dl()
        print(self.yq1())
        # 如果不是会员登录页就截图保存
        try:
            assert self.yq1() == '会员登录'
        except Exception as e:
            print(e)
            self.driver.save_screenshot('a.png')
        self.username()
        self.password()
        time.sleep(10)
        self.login_bt()
        # 强制等待5秒查看结果
        time.sleep(5)
        print(self.yq2())
        try:
            assert self.yq2() == '欢迎回来，19064013675'
        except Exception as e:
            print(e)
            self.driver.save_screenshot('b.png')

